package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.RbacManagerDao;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class RbacManagerServiceImpl implements RbacManagerService {
    @Autowired(required = false)
    RbacManagerDao rbacManagerDao;
    @Override
    public ResponseEntity findAll(int currentPage,int pageSize,RbacManager rbacManager) {
        //分页
        PageHelper.startPage(currentPage, pageSize);
        List<RbacManager> rbacManagerList = rbacManagerDao.findAll(rbacManager);
        PageInfo<RbacManager> of = PageInfo.of(rbacManagerList);
        ResponseEntity<PageInfo> listResponseEntity = new ResponseEntity<>();
        if (rbacManagerList.size()>0) {
            listResponseEntity.setData(of);
            listResponseEntity.setCode(200);
            listResponseEntity.setMsg("查询成功！");
        }else{
            listResponseEntity.setData(null);
            listResponseEntity.setCode(500);
            listResponseEntity.setMsg("数据为空");
        }
        return listResponseEntity;
    }

    @Override
    public ResponseEntity deleteOne(int id) {
        int num = rbacManagerDao.deleteById(id);
        if(num>0){
            return new ResponseEntity(200, "成功删除一行数据！", null);
        }else {
            return new ResponseEntity(500,"系统维护中",null);
        }
    }

    @Override
    public ResponseEntity addOne(RbacManager rbacManager) {
        int num = rbacManagerDao.addOne(rbacManager);
        if (num>0){
            return new ResponseEntity(200, "成功插入一行数据！", null);
        }else {
            return new ResponseEntity(500,"系统维护中",null);
        }
    }

    @Override
    public ResponseEntity updateOne(RbacManager rbacManager) {
        int num = rbacManagerDao.updateOne(rbacManager);
        if (num>0){
            return new ResponseEntity(200, "成功修改一行数据！", null);
        }else {
            return new ResponseEntity(500,"系统维护中",null);
        }
    }
}
